package com.aaa.controller;

import com.aaa.service.UmsAdminService;
import com.aaa.util.IDCard;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("umsAdmin")
public class UmsAdminController {

    @Resource
    UmsAdminService umsAdminService;

    @RequestMapping("selectUser")
    @ResponseBody
    public List<Map<String,Object>> toLogin(String username){
        return umsAdminService.selectUser(username);

    }

    @RequestMapping("updPwd")
    @ResponseBody
    public boolean updPwd(String id,String password){
        return umsAdminService.updPwd(id,new BCryptPasswordEncoder().encode(password))==1?true:false;
    }

    @RequestMapping(value = "getIdcard")
    @ResponseBody
    public String getIdcard(@RequestParam("file") MultipartFile file) {
        String filename = file.getOriginalFilename();
        String s = "";
        try {
            s = IDCard.getBase64FromInputStream(file.getInputStream());
            System.out.println(s);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }
}
